package net.NingXiaRuiTai.ShortChain.controller;


import net.NingXiaRuiTai.ShortChain.controller.request.ShortLinkAddRequest;
import net.NingXiaRuiTai.ShortChain.controller.request.ShortLinkDelRequest;
import net.NingXiaRuiTai.ShortChain.controller.request.ShortLinkPageRequest;
import net.NingXiaRuiTai.ShortChain.controller.request.ShortLinkUpdateRequest;
import net.NingXiaRuiTai.ShortChain.service.ShortLinkService;
import net.NingXiaRuiTai.ShortChain.utils.JsonData;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Yuan
 * @since 2025-02-16
 */
@RestController
@RequestMapping("/api/link/v1")
public class ShortLinkController {
    @Resource
    private ShortLinkService shortLinkService;
    @PostMapping("/add")
    public JsonData creatShortLink(@RequestBody ShortLinkAddRequest addRequest){

        JsonData jsonData= shortLinkService.creatShortLink(addRequest);
        return jsonData;

    }
    /**
     * 分页查找短链
     */

    @RequestMapping("page")
    public JsonData pageByGroupId(@RequestBody ShortLinkPageRequest request){


        Map<String,Object> result = shortLinkService.pageByGroupId(request);

        return JsonData.buildSuccess(result);

    }
    @RequestMapping("del")
    public JsonData delShortLink(@RequestBody ShortLinkDelRequest delRequest){
        JsonData jsonData= shortLinkService.delShortLink(delRequest);
        return jsonData;

    }
    @RequestMapping("Update")
    public JsonData updateShortLink(@RequestBody ShortLinkUpdateRequest updateRequest){
        JsonData jsonData= shortLinkService.updateShortLink(updateRequest);
        return jsonData;
    }

}

